<template>
  <div class="form-single-fragment" style="position: relative;">
    <div class="form-single-info">
      <div class="form-single-btn clearfix">
        <el-button type="primary" @click="submitForm('agree')" v-if="btnbox">同意</el-button>
        <el-button @click="submitForm('refuse')" v-if="btnbox">拒绝</el-button>
        <el-button @click="resetForm()">返回</el-button>
      </div>
      <div class="form-single-btn clearfix" style="right: 120px;" v-if="detailData.verifyStatus==2">
        <img src="@/assets/img/adopt.png" />
      </div>
      <el-form :model="detailData" ref="detailData" label-width="170px" size="mini" label-position="right">
        <h4 class="clearfix">
          <img class="fl" src="@/assets/img/icon_customer.png" />
        </h4>
        <el-row class="el-form-info">
          <el-col :span="12">
            <el-form-item label="单位名称：">{{detailData.customer.custName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户层级：">{{detailData.customer.custLevelName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位属性：">{{detailData.customer.unitAttributeName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户地区：">{{detailData.customer.districtName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业联系人：">{{detailData.customer.contacts}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话：">{{detailData.customer.telephone}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户职务：">{{detailData.customer.custPosition}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户生日：">{{detailData.customer.custBirthday}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户兴趣：">{{detailData.customer.custInterest}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维护周期：">{{detailData.customer.maintainCycle}}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="主要社会关系：">{{detailData.customer.mainSocialRelations}}</el-form-item>
          </el-col>
        </el-row>
        <h4 class="clearfix">
          <img class="fl" src="@/assets/img/icon_oppo.png" />
        </h4>
        <el-row class="el-form-info">
          <el-col :span="12">
            <el-form-item label="商机名称：">{{detailData.businessOpportunity.oppoName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商机地区：">{{detailData.businessOpportunity.oppoDistrictName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务类型：">{{detailData.businessOpportunity.businessTypeName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属阶段：">{{detailData.businessOpportunity.stageName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商机来源：">{{detailData.businessOpportunity.oppoSource}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="负责人：">{{detailData.businessOpportunity.directorName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参与人：">{{detailData.businessOpportunity.partnerNames||'--'}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预计合同额度（万元）：">{{detailData.businessOpportunity.contractAmount}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预计成交时间：">{{detailData.businessOpportunity.tradingDate}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否投标：">{{detailData.businessOpportunity.isBid=='1'?'是':'否'}}</el-form-item>
          </el-col>
          <!-- <el-col :span="12" v-if="detailData.businessOpportunity.isBid==1">
            <el-form-item label="投标标段：">{{detailData.businessOpportunity.bidSectionName}}</el-form-item>
          </el-col> -->
        </el-row>
      </el-form>
    </div>
    <div class="annotation" v-if="examineFrombox">
      <examineFrom ref="examineFrom" @getexamineFrom="getexamineFrom" v-model="examineFrombox"></examineFrom>
    </div>
  </div>
</template>

<script>
import { BusinessOpportunities, Customers } from '@/api/commercial.js';
import examineFrom from '@/components/selector/examineFrom.vue';
export default {
  name: 'OpportunitiesExamine',
  components: { examineFrom },
  data () {
    return {
      isShowloading: false,
      examineFrombox: false,
      btnbox: true,
      clueStatuslist: [
        {name: '输单', value: '-1'},
        {name: '进行中', value: '0'},
        {name: '待立项', value: '1'},
        {name: '已立项', value: '2'},
        {name: '立项审核', value: '3'},
        {name: '立项驳回', value: '4'}
      ],
      detailData: {
        customer: {},
        businessOpportunity: {}
      },
      tableData: [],
      ruleForm: {
        flowTaskCommentDto: {
          approvalType: '',
          comment: ''
        },
        id: '',
        taskId: ''
      }
    };
  },
  created () {
  },
  mounted () {
    if (this.$route.query.businessKey) {
      this.ruleForm.id = this.$route.query.businessKey
      this.ruleForm.taskId = this.$route.query.taskId
      this.loadDetailWidgetData()
    }
    if (this.$route.query.taskdetail) {
      this.btnbox = false
    }
  },
  methods: {
    /**
     * 商机详情
     */
    loadDetailWidgetData () {
      let params = this.$route.query.businessKey;
      return new Promise((resolve, reject) => {
        BusinessOpportunities.detail(this, params).then(res => {
          this.detailData.businessOpportunity = res.data
          this.loadCustomerdetail(res.data.customerId)
        }).catch(e => {
          reject(e);
        });
      });
    },
    /**
     * 客户详情
     */
    loadCustomerdetail (customerId) {
      let params = customerId
      return new Promise((resolve, reject) => {
        Customers.detail(this, params).then(res => {
          this.detailData.customer = res.data
        }).catch(e => {
          reject(e);
        });
      });
    },
    /**
     * 审批
     */
    submitForm (data) {
      this.ruleForm.flowTaskCommentDto.approvalType = data
      this.examineFrombox = true
      this.$nextTick(() => {
        this.$refs.examineFrom.info()
      })
    },
    getexamineFrom (data) {
      this.isShowloading = true;
      this.ruleForm.flowTaskCommentDto.comment = data.comment
      let params = this.ruleForm;
      return new Promise((resolve, reject) => {
        BusinessOpportunities.submitUserOpportunities(this, params).then(res => {
          this.$message({
            showClose: true,
            message: '操作成功！',
            type: 'success'
          });
          this.resetForm()
        }).catch(e => {
          reject(e);
        });
      });
    },
    resetForm () {
      this.$router.go(-1)
    }
  }
}
</script>
<style lang="scss" scoped>
  h3{border-bottom: 1px solid #E9E9EB;padding: 0 0 10px;}
  .table_container{margin: 10px 0;}
  .form-single-info{width: 90%;margin: 0 auto;}
  /deep/.el-tabs__nav{left: inherit;}
  /deep/.el-tabs__item{text-align: center;}
  /deep/.el-tabs__nav-wrap::after{display: none;}
  /deep/.el-tabs__item.is-active{color: #051D69;font-weight: bold;}
  /deep/.el-tabs__active-bar{background-color: #051D69;}
  .form-single-btn{position: absolute;right: 20px;top: 20px;z-index: 20;}
</style>
